<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Admin_model extends CI_Model{
		
		function __construct()
		{
			parent::__construct();
			$this->table = 'admin';
			$this->group = 'admin_group';
		}
		
		
		function Get($uid = '')
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where(array($this->table.'.id'=>$uid))
			  ->or_where($this->table.'.username' ,$uid)
			  //->join($this->group, $this->table.'.group_id = '.$this->group.'.id', 'left')
			  ->get()
			  ->row_array();
		}
		function GetAll($group_id = '')
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where(array($this->table.'.group_id'=>$group_id))
			  ->get()
			  ->result_array();
		}
		public function get_count($where){
			$this->db->select('*');
			$this->db->from($this->table);
			$this->db->where($where);
			$this->db->order_by("id", "desc");
			$query = $this->db->get();
			return $query->num_rows();
		}
		
		public function get_list($where,$page,$limit)
	    {
			$this->db->select($this->group.'.group_name,'.$this->table.'.*');
			$this->db->from($this->table);
			$this->db->join($this->group, $this->table.'.group_id = '.$this->group.'.id', 'left');
			$this->db->where($where);
			$this->db->order_by($this->table.".id", "asc");
			$this->db->limit($limit, $page);
			$query = $this->db->get();
			return $query->result_array(); 
	    }
		
		public function getlist($where)
	    {
			$this->db->select('*');
			$this->db->from($this->table);
			$this->db->where($where);
			$this->db->order_by("id", "asc");
			$query = $this->db->get();
			return $query->result_array(); 
	    }
		
		function get_user_by_uid($uid = 0)
		{
			return $this->db->where('id',$uid)->get($this->table)->row_array();
		}
		
		function insert($data)
		{
			$this->db->insert($this->table, $data);
			return $this->db->affected_rows();
		}
		
		function update($data)
		{
			return $this->db->where('id',$this->session->userdata('id'))->update($this->table, $data);
		}
		
		function userupdate($data,$id)
		{
			return $this->db->where('id',$id)->update($this->table, $data);
		}
		
		function setstate($state,$ids)
		{
			return $this->db->where_in('id',$ids)->update($this->table, array('state'=>$state));
		}
		
		function update_user_password()
		{
			$data['password'] = md5($this->input->post('new_pass'));
			$this->db->where('uid',$this->session->userdata('uid'))->update('blka_admins', $data);		
		}
		
		function delete($delid)
		{	
			$this->db->where('id',$delid);
			$this->db->delete($this->table);
			return $this->db->affected_rows();
		}
	}